package com.linkhouse.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.linkhouse.domain.bo.TbUserBO;
import com.linkhouse.domain.po.TbUser;
import com.linkhouse.mapper.TbUserMapper;
import com.linkhouse.service.TbUserService;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class TbUserServiceImpl implements TbUserService {

    @Autowired
    private TbUserMapper tbUserMapper;
    @Resource
    private RocketMQTemplate rocketMQTemplate;

    @Override
    public TbUserBO query(Long id) {
        TbUser tbUser = tbUserMapper.selectById(id);
        TbUserBO tbUserBO = new TbUserBO();
        BeanUtils.copyProperties(tbUser,tbUserBO);
        return tbUserBO;
    }

    @Override
    public void updatephone(TbUserBO tbUserBO) {

        if(tbUserBO.getPhone() != null){
            TbUser tbUser = tbUserMapper.selectById(tbUserBO.getId());
            rocketMQTemplate.convertAndSend("Phone",tbUser.getPhone());
        }
        TbUser tbUser = new TbUser();
        BeanUtils.copyProperties(tbUserBO,tbUser);
        tbUserMapper.updateById(tbUser);
    }

    @Override
    public void delete(Long id) {
        tbUserMapper.deleteById(id);
    }
}
